package club.jdiy.core.convert;

import java.math.BigDecimal;
import java.math.BigInteger;

class DoubleConverter  extends NumberConverter<Double> {
    public DoubleConverter(Double source) {
        super(source);
    }

    @Override
    public Double getSource() {
        return source;
    }

    @Override
    public Boolean getBoolean() {
        return source!=0;
    }

    @Override
    public Byte getByte() {
        if (source > Byte.MAX_VALUE || source < Byte.MIN_VALUE) {
            throw __throw(Byte.class);
        } else {
            return source.byteValue();
        }
    }

    @Override
    public Short getShort() {
        if (source > Short.MAX_VALUE || source < Short.MIN_VALUE) {
            throw __throw(Short.class);
        } else {
            return source.shortValue();
        }
    }

    @Override
    public Integer getInteger() {
        if(source>Integer.MAX_VALUE || source<Integer.MIN_VALUE){
            throw __throw(Integer.class);
        }else{
            return source.intValue();
        }
    }

    @Override
    public Long getLong() {
       return Math.round(source);
    }

    @Override
    public Double getDouble() {
        return getSource();
    }

    @Override
    public BigDecimal getBigDecimal() {
        return BigDecimal.valueOf(source);
    }


    @Override
    public BigInteger getBigInteger() {
        return BigInteger.valueOf(getLong());
    }

}
